$(function(){
    //百度地图API功能
    var map = new BMap.Map("allmap");
    map.addControl(new BMap.NavigationControl());
    map.enableScrollWheelZoom();    //启用滚轮放大缩小
    map.enableContinuousZoom();    //启用地图惯性拖拽
    //map.setZoom(10);
    api.solo( "siteInfo", [], function(d){
        var siteInfo= d.data;
        map.centerAndZoom(new BMap.Point(siteInfo.lon,siteInfo.lat),11);
    });
    map.centerAndZoom(new BMap.Point(117.565297,33.547786),13);

    api.solo( "serviceList", [], function(d){
        for(var i in d.data.list){
            serviceInfo=d.data.list[i];
            console.log(serviceInfo);
            var point = new BMap.Point(serviceInfo.longitude,serviceInfo.latitude);
            var marker = new BMap.Marker(point);  // 创建标注
            map.addOverlay(marker);              // 将标注添加到地图中
            var score=serviceInfo.comment==0?5:serviceInfo.score/serviceInfo.comment
            var opts = {
                width : 200,     // 信息窗口宽度
                height: 100,     // 信息窗口高度
                title : serviceInfo.service_name ,
                enableMessage:false,
                'message': serviceInfo.tel+"评价"+score+"星"
            };
            var s="<br/><a href='"+_root+"../my/setDefaultService?service_id="+serviceInfo.id+"'>设置默认服务站</a>";
            marker.infoWindow = new BMap.InfoWindow(serviceInfo.tel+"评价"+score+"星"+s, opts);  // 创建信息窗口对象
            marker.addEventListener("click", function(e){
                var p = e.target;
                map.openInfoWindow(p.infoWindow, p.getPosition()); //开启信息窗口
            });
        }
    });
});
